﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;   

namespace ClientLib
{
    public class ClientConfig
    {
        //file config
        public string m_rootfolder = "c:\\TinyApp\\TinyCC";
        public string m_configfolder = "localhost";
        public string m_InstanceName = "";
        public string m_moduleIP = "";
        public int m_modulePort = 0;
        public string m_serverIP = "";
        public int m_serverPort = 0;

        //runtime config
        public string m_userName;
        public string m_ModuleName;
        public string m_ModuleType;
        public string m_region;

        private    System.Xml.XmlDocument m_configDoc;

        public bool readConfig(string fileName)
        {
            fileName = m_rootfolder+"//"+m_configfolder+"//"+fileName;
            m_configDoc = new System.Xml.XmlDocument();
            try
            {
                m_configDoc.Load(fileName);
                System.Xml.XmlNode node = m_configDoc.SelectSingleNode("CCClient//Instance//Name");
                if (node != null)
                    m_InstanceName = node.InnerText;

                node = m_configDoc.SelectSingleNode("CCClient//Instance//ModuleIP");
                if (node != null)
                    m_moduleIP = node.InnerText;

                node = m_configDoc.SelectSingleNode("CCClient//Instance//ModulePort");
                if (node != null)
                    m_modulePort = int.Parse(node.InnerText);

                node = m_configDoc.SelectSingleNode("CCClient//Instance//ServerIP");
                if (node != null)
                    m_serverIP = node.InnerText;

                node = m_configDoc.SelectSingleNode("CCClient//Instance//ServerPort");
                if (node != null)
                    m_serverPort = int.Parse(node.InnerText);
            }
            catch
                {
                    //error read config file
                    return false;
                }

            return true;
        }
    }
    
}
